package com.lianxi.jdbc;

import org.apache.tomcat.dbcp.dbcp.BasicDataSource;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * Created by Administrator on 2018/4/26 0026.
 */
public class DBHelper {
    private static BasicDataSource ds = new BasicDataSource();

    static {
        String driver = "com.mysql.cj.jdbc.Driver";
        // 扶贫办数据库
        /*String url = "jdbc:mysql://10.10.10.249:13306/fupinban?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT&useSSL=false&failOverReadOnly=false";
        String user = "fupinban";
        String pwd = "u-eUaS2QK0WF";*/
        // t1consult测试线数据库
        /*String url = "jdbc:mysql://222.143.21.208:6666/t1consult?useUnicode=true&characterEncoding=utf-8";
        String user = "henant1";
        String pwd = "nfkwTu38N67WZFu";*/
        // 广电局数据库
//        String url = "jdbc:mysql://10.10.10.249:13306/hnxwcb?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT&useSSL=false&failOverReadOnly=false";
//        String user = "hnxwcb";
//        String pwd = "9843jflPMY47h";

        // 广电局增量
        /*String url = "jdbc:mysql://10.10.10.249:13306/hnxwcb2?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT&useSSL=false&failOverReadOnly=false";
        String user = "hnxwcb2";
        String pwd = "9843jflPMY47h";*/

        // 河南财政厅cms
        /*String url = "jdbc:mysql://10.10.10.249:13306/hnczcms?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT&useSSL=false&failOverReadOnly=false";
        String user = "hnczcms";
        String pwd = "hnczcmspasswd";*/

        // 安阳市司法局
        /*String url = "jdbc:mysql://10.10.10.249:13306/ayssfj?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT&useSSL=false&failOverReadOnly=false";
        String user = "ayssfj";
        String pwd = "9843jflPMY47h";*/

        // 教育厅思政处
/*        String url = "jdbc:mysql://10.10.10.249:13306/sizhengchu?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT&useSSL=false&failOverReadOnly=false";
        String user = "sizhengchu";
        String pwd = "8476d1c93e33e2a0";*/

        // 潢川县
        /*String url = "jdbc:mysql://10.10.10.249:13306/cmsonehc?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT&useSSL=false&failOverReadOnly=false";
        String user = "cmsonehc";
        String pwd = "9843jflPMY47h";*/
        // 息县
   /*     String url = "jdbc:mysql://10.10.10.249:13306/xixian?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT&useSSL=false&failOverReadOnly=false";
        String user = "xixian";
        String pwd = "9843jflPMY47h"*/;

        String url = "jdbc:mysql://127.0.0.1:3306/zx_luohe?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false";
        String user = "root";
        String pwd = "root";

        // 发改委子站
//        String url = "jdbc:mysql://10.10.10.249:13306/fgwzz?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT&useSSL=false&failOverReadOnly=false";
//        String user = "fgwzz";
//        String pwd = "dePdnt873bn47dw";



        String initSize = "5";
        String maxSize = "60000";
        //创建连接池
        ds = new BasicDataSource();
        //设置参数
        ds.setDriverClassName(driver);
        ds.setUrl(url);
        ds.setUsername(user);
        ds.setPassword(pwd);
        ds.setInitialSize(new Integer(initSize));
        ds.setMaxActive(new Integer(maxSize));
    }

    public static Connection getConnection() throws SQLException {
        return ds.getConnection();
    }

    public static void close(Connection conn) {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
                throw new RuntimeException("关闭连接失败", e);
            }
        }
    }


}
